﻿using IOA.MES.Business;
using IOA.MES.ClientApi.Models.Request.WorkOrder;
using IOA.MES.Common;
using NLog;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace IOA.MES.ClientApi.Controllers
{
    public class WorkOrderController : ApiController
    {
        private Logger logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// 查询设备列表
        /// </summary>
        [HttpPost]
        public ResultJson<List<string>> QueryWorkshopWorkOrders([FromBody] object request)
        {
            var result = new WorkOrderMgr().QueryWorkshopWorkOrders(0, 0, BaseEnv.WorkshopCode);

            return new ResultJson<List<string>>(result.Item2.Select(_ => _.WorkOrderNo).Distinct().ToList(), result.Item1);
        }

        /// <summary>
        /// 获取最新条码
        /// </summary>
        [HttpPost]
        public ResultJson<string> GetNewBarCode([FromBody] GetNewBarCodeRequest request)
        {
            var barCode = new WorkOrderMgr().GetNewBarCode(request.MachineId, request.WorkOrderNo, BaseEnv.User.PkId);

            return new ResultJson<string>(barCode);
        }

        /// <summary>
        /// 核验补打条码权限
        /// </summary>
        [HttpPost]
        public ResultJson<object> CheckRePrintBarCode([FromBody] CheckRePrintBarCodeRequest request)
        {
            new WorkOrderMgr().CheckRePrintBarCode(request.UserName, request.Password, request.WorkOrderNo, request.BarCode);
            return new ResultJson<object>();
        }
    }
}
